package org.web.accesscontrollist.server.service;

import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.web.accesscontrollist.server.domain.AclBusinessLineDO;
import org.web.accesscontrollist.server.domain.query.QueryAclBusinessLine;
import org.web.base.domain.exception.ResultMessageEnum;
import org.web.base.domain.helper.ServiceExceptionHelper;

import javax.annotation.Resource;

@Service("operatorService")
public class OperatorService {

    @Resource
    private AclBusinessLineService aclBusinessLineService;

    public void judgeOperatorByAccessKey(String businessLine, String accessKey) {
        QueryAclBusinessLine queryAclBusinessLine = new QueryAclBusinessLine();
        queryAclBusinessLine.setBusinessLine(businessLine);
        queryAclBusinessLine.setAccessKey(accessKey);
        AclBusinessLineDO aclBusinessLineDOFromDB = aclBusinessLineService.selectOneAclBusinessLine(queryAclBusinessLine);
        if (ObjectUtils.isEmpty(aclBusinessLineDOFromDB)) {
            throw ServiceExceptionHelper.buildServiceException(ResultMessageEnum.DATA_NO_PRIVILEGE, "根据accessKey校验权限，没有业务线操作权限。");
        }
    }

}
